package com.sxyc.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.sxyc.common.ResultData;

public class ResultUtils {

	private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(ResultUtils.class);

	public static String getResult(int code, String message, Object data) {
		String str = "";
		ResultData resultData = new ResultData(code, message, data);
		ObjectMapper mapper = new ObjectMapper();
		try {
			str = mapper.writeValueAsString(resultData);
		} catch (JsonProcessingException e) {
			e.printStackTrace();
			logger.error("getResult is error！", e);
		}
		return str;
	}

	public static String getSuccessResult(int code, String message, Object data) {
		return getResult(code, message, data);
	}

	public static String getSuccessResult(String message, Object data) {
		return getResult(0, message, data);
	}

	public static String getSuccessResult(int code, String message) {
		return getResult(code, message, null);
	}

	public static String getSuccessResult(String message) {
		return getResult(0, message, null);
	}

	public static String getSuccessResult(Object data) {
		return getResult(0, "操作成功！", data);
	}

	public static String getSuccessResult() {
		return getResult(0, "操作成功！", null);
	}

	public static String getFailureResult(int code, String message) {
		return getResult(code, message, null);
	}

	public static String getFailureResult(String message) {
		return getResult(-1, message, null);
	}

	public static String getFailureResult() {
		return getResult(-1, "操作失败！", null);
	}

}
